package com.epoch.zuul.auth.service.impl;

import bean.response.ResponseBean;
import bean.response.ResultEnum;
import com.epoch.zuul.auth.dao.ConsumerDao;
import com.epoch.zuul.auth.dao.CsRoleDao;
import com.epoch.zuul.auth.dao.RolesDao;
import com.epoch.zuul.auth.role.CsRole;
import com.epoch.zuul.auth.role.Roles;
import com.epoch.zuul.auth.service.CsRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import utils.ResultInfoUtil;

import java.util.HashMap;
import java.util.List;

/**
 * @author admin
 */
@Service
public class CsRoleServiceImpl implements CsRoleService {

    @Autowired
    private CsRoleDao csRoleDao;

    @Autowired
    private ConsumerDao consumerDao;

    @Autowired
    private RolesDao rolesDao;

    @Override
    public void updateCsRole(String currentCsId, String csId, String roleId) {
        csRoleDao.updateCsRole(currentCsId,csId,roleId);
    }

    @Override
    public CsRole getRoleId(String csId) {
        return csRoleDao.getRoleId(csId);
    }

    @Override
    public List<Roles> getRolesByCsPhone(String csPhone) {
        return csRoleDao.getRolesByCsPhone(csPhone);
    }

    @Override
    public ResponseBean updateCsRoleByCsIdRoleId(HashMap<String, String> map) {
        Integer id = consumerDao.getById(map.get("csId")).getId();
        Integer roleId = Integer.parseInt(map.get("roleId"));
        csRoleDao.updateCsRoleByCsIdRoleId(id,roleId);
        return ResultInfoUtil.buildSuccess(ResultEnum.OK,"为用户修改身份的成功",null);
    }
}
